package huixue.cn.com.rxapp.login.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import butterknife.BindView;
import butterknife.OnClick;
import huixue.cn.com.library.entity.BaseHttpResult;
import huixue.cn.com.library.helper.EditTextHelper;
import huixue.cn.com.library.listener.SimpleTextWatcher;
import huixue.cn.com.library.observer.BaseObserver;
import huixue.cn.com.library.observer.SimpleObserver;
import huixue.cn.com.library.util.ToastUtils;
import huixue.cn.com.rxapp.R;
import huixue.cn.com.rxapp.api.RetrofitService;
import huixue.cn.com.rxapp.base.BaseActivity;
import huixue.cn.com.rxapp.base.BasePresent;
import huixue.cn.com.rxapp.base.IBaseUI;
import huixue.cn.com.rxapp.entity.HttpExtResult;
import huixue.cn.com.rxapp.entity.HttpResult;
import huixue.cn.com.rxapp.login.present.LoginPresenter;
import huixue.cn.com.rxapp.util.HttpUiTips;
import huixue.cn.com.rxapp.util.LogUtils;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class LoginActivity extends BaseActivity<LoginPresenter,LoginPresenter.LoginUI> implements LoginPresenter.LoginUI {

    @BindView(R.id.et_username)
    EditText etUsername;
    @BindView(R.id.et_password)
    EditText etPassword;
    @BindView(R.id.btn_login)
    Button btnLogin;

    @Override
    public int getLayout() {
        return R.layout.activity_login;
    }

    @Override
    public void initView() {
        EditTextHelper.getEditTextDeleteIconWrapper(this, etUsername).setTextWatcher(mTextWatcher);
        EditTextHelper.getEditTextDeleteIconWrapper(this, etPassword).setTextWatcher(mTextWatcher);
    }

    @Override
    public void addEvent() {

    }

    @OnClick(R.id.btn_login)
    public void onViewClicked(View view) {
        switch (view.getId()){
            case R.id.btn_login:
            {
                getPresenter().login(etUsername.getText().toString(),etPassword.getText().toString());
                break;
            }
            default:
                break;
        }
    }

    SimpleTextWatcher mTextWatcher = new SimpleTextWatcher(){
        @Override
        public void afterTextChanged(Editable s) {
            super.afterTextChanged(s);
            if(!TextUtils.isEmpty(etPassword.getText().toString().trim())
                    && !TextUtils.isEmpty(etUsername.getText().toString().trim())){
                btnLogin.setEnabled(true);
            }
        }
    };

    @Override
    protected LoginPresenter createPresenter() {
        return new LoginPresenter();
    }

    @Override
    protected LoginPresenter.LoginUI getUI() {
        return this;
    }


    /*@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LogUtils.e("==Login==onCreate==");
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        LogUtils.e("==Login==onSaveInstanceState==");
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        LogUtils.e("==Login==onRestoreInstanceState==");
    }

    @Override
    protected void onStart() {
        super.onStart();
        LogUtils.e("==Login==onStart==");
    }

    @Override
    protected void onResume() {
        super.onResume();
        LogUtils.e("==Login==onResume==");
    }

    @Override
    protected void onPause() {
        super.onPause();
        LogUtils.e("==Login==onPause==");
    }

    @Override
    protected void onStop() {
        super.onStop();
        LogUtils.e("==Login==onStop==");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        LogUtils.e("==Login==onDestroy==");
    }*/

}
